package demo7;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.net.Socket;

/*
* 了解容器管理对象时声明周期对应的各个方法
* */
@Component
public class Person implements InitializingBean, DisposableBean {
    private String name;
    private int age;
    private Socket socket;

    @Value("18")
    public void setAge(int age) {
        System.out.println("2:Person()实例对象，setage（）执行了");
        this.age = age;
    }

    public Person(){
        System.out.println("1:Person()的构造器执行了");
    }
    @Value("张三")
    public void setName(String name) {
        System.out.println("2:Person()实例对象,seName（）执行了");
        this.name = name;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("3:Person对象被容器完整初始化完毕了");

    }

    public void  play(){
        System.out.println("4:Person中的正常功能方法play（）方法执行了");
    }


    @Override
    public void destroy() throws Exception {
        System.out.println("5：容器即将销毁，通知Person，调用destory");
    }
}
